
import { createRouter, createWebHistory } from 'vue-router';
import { generateRoutesFromDirectory } from '@/utils/index'
import Home from '../views/Home.vue';

let routes = [

  {
    path: '/Home',
    name: 'home',
    component: Home,
    meta:{
      title:'首页'
    },
    children:[
      {
        path: '/about',
        name: 'about',
        meta:{
          title:'关于学号和电话'
        },
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () =>
          import(/* webpackChunkName: "about" */ '../views/AboutView.vue'),
      },
    ]
  },
  {
    path: '/',
    name: '',
    redirect:'/HomeGuide'
  },
  {
    path: '/HomeGuide',
    name: 'HomeGuide',
    meta:{
      title:'首页引导'
    },
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () =>
      import(/* webpackChunkName: "about" */ '../views/HomeGuide.vue'),
  },
];

/* 动画版路由 */
// const routesFromAnimationBoard = import.meta.glob('../views/AnimationBoard/*.vue');
// let animationRouteObj =  generateRoutesFromDirectory(routesFromAnimationBoard, {
//   path: '/AnimationBoard',
//   meta:{
//     title: '动画板',
//   },
//   children:[]
// });
//
// routes[0].children.push(animationRouteObj)

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes,
});


router.beforeEach((to, from,next) => {
  if (router.hasRoute(to.name)) {
    next(); // 路由存在，继续导航
  } else {
    next('/HomeGuide'); // 路由不存在，跳转到 404 页面
  }
});

export default router;
export {
  routes,
};

